import http from "../libs/request";

import { ApiResp } from "../types/model";
import { IUser } from "../types/user";
import {
  IUserLoginReq,
  IUserRegisterReq,
  IChangePasswordReq,
} from "../types/userReq";

export async function login(loginReq: IUserLoginReq) {
  const { data } = await http.post("/api/user/login", loginReq);
  return data;
}

export async function register(registerReq: IUserRegisterReq) {
  const { data } = await http.post("/api/user/register", registerReq);
  return data;
}

export async function logout() {
  const { data } = await http.post("/api/user/logout");
  return data;
}

export async function getUserInfo() {
  const { data } = await http.get<ApiResp<IUser>>("/api/user/info");
  return data;
}

export async function changepwd(changePwdReq: IChangePasswordReq) {
  const { data } = await http.post("/api/user/changepwd", changePwdReq);
  return data;
}
